package cn.edu.zzuli.nothinglink.mapper;

import cn.edu.zzuli.nothinglink.entity.WorkSubmitRecord;
import cn.edu.zzuli.nothinglink.mapper.provider.WorkSubmitRecordProvider;
import cn.edu.zzuli.nothinglink.to.StuSubmitInfoTo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author suzyyy
 * @since 2021-04-08
 */
public interface WorkSubmitRecordMapper extends BaseMapper<WorkSubmitRecord> {

    @SelectProvider(type = WorkSubmitRecordProvider.class, method = "getWorkIdsByInfo")
    List<Integer> getWorkIdsByInfo(@Param("workIds")List<Integer> workIds, @Param("stuId") Integer stuId);


    @Select("<script>" +
            "SELECT count(*) as submit_count, sum(ws.score) as score_count " +
            "FROM work_submit_record ws WHERE ws.ws_stu_id = #{stuId} and ws.work_id in (" +
            "<foreach collection='workIds' item='item' index='index' separator=',' >" +
                "#{item}" +
            "</foreach> " +
            ")" +
            "</script>")
    @Results(
            id = "submitInfo",
            value = {
                    @Result(property = "submitCount",column = "submit_count"),
                    @Result(property = "scoreCount",column = "score_count")
            }
    )
    StuSubmitInfoTo getStusSubmitInfo(@Param("stuId") Integer stuId, @Param("workIds") Set<Integer> workIds);

    @Select("<script>" +
            "SELECT * " +
            "FROM work_submit_record ws WHERE ws.work_id in (" +
            "<foreach collection='workIds' item='item' index='index' separator=',' >" +
            "#{item}" +
            "</foreach> " +
            ")" +
            "</script>")
    List<WorkSubmitRecord> getWorkSubmitRecordInCourse(@Param("workIds") List<Integer> workId);
}
